﻿using System;
using System.Collections.Generic;

namespace EduardoMessias.DevTools
{
    public abstract class Multiton<T> where T : class, new()
    {
        private static T _instance;
        private static Dictionary<object, T> _instances = new Dictionary<object, T>();

        public static T GetInstance(object key)
        {
            lock (_instances)
            {
                if (_instances.TryGetValue(key, out _instance))
                    return _instance;

                _instance = Activator.CreateInstance<T>();
                return _instance;
            }
        }
    }
}
